Subject: Re: Exec RawDoFmt
From: [email-masked] (Doug Walker)
Date: Wed, 12 May 1993 17:23:30 GMT
Newsgroups: comp.sys.amiga.programmer

In article <[email-masked]>, [email-masked] (Bjorn Reese) writes:
|> > In article <[email-masked]>, [email-masked] (Miles  
|> Willmek) writes:
|> > >Can somebody help me with Exec's RawDoFmt() function.  I cant seem to get
|> > >string types (%s, %b)to output anything (except spaces if I specify a field
|> > >width.
|> > >
|> > >I'm pretty sure its not my code.  Does RawDoFmt() work?
|> 
|> The parameter for %s (strings) must be a pointer to the string,
|> not the string itself, as in Printf().

The "string itself" and the "pointer to the string" are actually the
same thing in C.  A string literal is really a char * that points to
the beginning of the string.  Hence, the parameter for %s is the same
for Printf() and RawDoFmt().

Here is example code that uses RawDoFmt() to print a string and a
decimal value.  BE CAREFUL when printing integers if you use four-byte
integers (the default for SAS/C and most other compilers) - unlike 
normal C, you must use %ld instead of %d when printing "int" variables
and constants if you use RawDoFmt().

#include <stdarg.h>
#include <string.h>
#include <clib/dos_protos.h>
#include <clib/exec_protos.h>
#include <pragmas/dos_pragmas.h>
#include <pragmas/exec_pragmas.h>

extern struct Library *DOSBase;

int myprintf(char *ctl, ...);

int main(void)
{
   myprintf("This is a %s (%ld)\n", "test", 42);
   return 0;
}

int myprintf(char *ctl, ...)
{
   char buffer[256];
   va_list args;

   va_start(args, ctl);

   /*********************************************************/
   /* NOTE: The string below is actually CODE that copies a */
   /*       value from d0 to A3 and increments A3:          */
   /*                                                       */
   /*          move.b d0,(a3)+                              */
   /*          rts                                          */
   /*                                                       */
   /*       It is essentially the callback routine needed   */
   /*       by RawDoFmt.                                    */
   /*********************************************************/

   RawDoFmt(ctl, args, (void (*))"\x16\xc0\x4e\x75", buffer);

   va_end(args);

   Write(Output(), buffer, strlen(buffer));

   return 0;
}

-- 
  *****                    / [email-masked]
 *|_o_o|\\     Doug Walker<  BIX, Portal: djwalker
 *|. o.| ||                \ CompuServe: 71165,2274
  | o  |//     
  ====== 
Any opinions expressed are mine, not those of SAS Institute, Inc.